#include "Transaction.h"

Transaction::Transaction() : operations(std::make_unique<std::vector<Operation>>()) {}

void Transaction::addOperation(const Operation& operation) {
    this->operations->push_back(operation);
}

std::vector<Operation> Transaction::getOperations() const {
    return *this->operations;
}

/**
void Transaction::execute(Db& db, std::vector<std::shared_mutex>& rowReadLocks, std::vector<std::shared_mutex>& rowWriteLocks) {
    for (auto& operation : this->operations) {
        std::cout << "Executing operation: " << operation << std::endl;
        // read operation
        if (operation.getOperationType() == 0) {
            rowReadLocks.at(operation.getRowNum()).lock();
            operation.setValue(db.read(operation.getRowNum()));
        // write operation
        } else {
            rowWriteLocks.at(operation.getRowNum()).lock();
            db.write(operation.getRowNum(), operation.getValue());
        }
    }
    // unlock all locks
    for (auto& operation : this->operations) {
        if (operation.getOperationType() == 0) {
            rowReadLocks.at(operation.getRowNum()).unlock();
        } else {
            rowWriteLocks.at(operation.getRowNum()).unlock();
        }
    }
}
*/